# ********************************************
# Program must run in virtual env
# (venv)christian@Ubuntu-VirtualBox:/...
#    ^-------
# ********************************************

from flask import Flask
from flask import render_template

import socket

app = Flask(__name__)

TCP_IP = '192.168.1.30'
TCP_PORT = 23
BUFFER_SIZE = 1024

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/on/')
def on(name=None):
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((TCP_IP, TCP_PORT))
  s.send(b"CTH\n")
  print("CTH\n")
  s.close()
  return render_template('home.html')

@app.route('/off/')
def off(name=None):
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((TCP_IP, TCP_PORT))
  s.send(b"CTL\n")
  s.close()
  print("CTL\n")
  return render_template('home.html')

# tells your operating system to listen on a public IP.
if __name__ == '__main__':
  app.run(host='0.0.0.0', port=5001)





